import { Nodes } from '@knno/dom';
import { ResizeType, Textarea as UITextarea } from '../components/textarea/textarea';
import { JSXProps } from '@knno/dom/jsx';
import { AttrCheck, isBool, isNumber, isStr, jsxBuild } from './utils';

export { UITextarea };

interface TextareaProps extends JSXProps<UITextarea> {
	placeholder?: string;
	readonly?: boolean;
	maxLength?: number;
	lines?: number;
	maxLines?: number;
	/**
	 * default value is 'auto'
	 */
	resize?: ResizeType;
	value?: string;
	disabled?: boolean;
	invalid?: boolean;
}

const ATTRS: AttrCheck = {
	placeholder: isStr,
	readonly: isBool,
	maxLength: isNumber,
	lines: isNumber,
	maxLines: isNumber,
	resize: isStr,
	value: isStr,
	invalid: isBool,
};

export function Textarea(props: TextareaProps, children: Nodes[]): UITextarea {
	return jsxBuild(new UITextarea(), props, children, ATTRS);
}
